﻿using MediatR;
using Return.Enum;
using SlaughterItem.Common.Infrastructures.Interfaces;
using THE_WIND_RISES.Common.Domans.Produce.Resources;
using THE_WIND_RISES.Common.Dtos;

namespace Production_Set.API.Application.Commands.Resourctes
{
    /// <summary>
    /// 资源管理删除(逻辑删除)
    /// </summary>
    public class ResourceDeleteHandler : IRequestHandler<ResourceDeleteCommend, Result>
    {
        private readonly IBaseRepository<Resource> Resource;

        public ResourceDeleteHandler(IBaseRepository<Resource> Resource)
        {
            this.Resource = Resource;
        }

        public async Task<Result> Handle(ResourceDeleteCommend request, CancellationToken cancellationToken)
        {
            var results = new Result() { Code = (int)CommonErrorCodes.Delete };

            string sql = "UPDATE Resource SET IsDelete=1 WHERE ResourceId=" + request.ResourceId;
            var list= Resource.Update(sql, results);
            if (list != null)
            {
                results.Code = (int)CommonErrorCodes.Success;
                results.Msg = "删除成功";
            }

            return results;
        }
    }
}
